# -*- coding:utf-8 -*-

import selenium.webdriver
from selenium.webdriver.support.ui import Select
from time import sleep
from extScript.UploadPic import UploadPic


class GYJSYD():
    def __init__(self):
        pass

    def test_gyjsd(self, driver, dist=None):
        Select(driver.find_element_by_id("immovablesClass")).select_by_visible_text("国有建设用地使用权")
        Select(driver.find_element_by_id("areause-type")).select_by_visible_text(dist["不动产类型2"])
        driver.find_element_by_id("immovablesDetail").clear()
        driver.find_element_by_id("immovablesDetail").send_keys(dist["不动产具体描述"])
        Select(driver.find_element_by_id("immovablesGetWay")).select_by_visible_text(dist["不动产取得方式"])
        driver.find_element_by_id("immovablesLoc").clear()
        driver.find_element_by_id("immovablesLoc").send_keys(dist["不动产坐落"])
        driver.find_element_by_id("immovablesArea").clear()
        driver.find_element_by_id("immovablesArea").send_keys(dist["面积"])

        if dist["证件类型"] == "不动产证号":
            driver.find_element_by_id("immovablesNo").clear()
            driver.find_element_by_id("immovablesNo").send_keys(dist["不动产证号"])
        else:
            driver.find_element_by_id("landNo1").clear()
            driver.find_element_by_id("landNo1").send_keys(dist["土地证号"])

        driver.find_element_by_name("stateOwnedBuildLand.attachHouse").click()
        # driver.find_element_by_id("houseNo1").clear()
        # driver.find_element_by_id("houseNo1").send_keys(dist["不动产证号"])
        driver.find_element_by_id("rest-years").clear()
        driver.find_element_by_id("rest-years").send_keys(dist["剩余年限"])

        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)

        driver.find_element_by_name("interestedPartyView").click()

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["利害关系人意见证明材料"]).upfile(
            "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/a")

        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        driver.find_element_by_id("textarea2").clear()
        driver.find_element_by_id("textarea2").send_keys(dist["备注"])

        driver.find_element_by_id("next-step2").click()


if __name__ == '__main__':
    a = GYJSYD()
    a.test_gyjsd()
